package com.sunnypower.rushfitapp.Coachpart;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sunnypower.rushfitapp.R;
import com.sunnypower.rushfitapp.entity.VReservecourse;

import java.util.List;


public class CourseListAdapter extends BaseAdapter {

    private List<VReservecourse> mList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;


    public CourseListAdapter(Context context, List<VReservecourse> list) {
        mContext = context;
        mList = list;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.course_list_item, null);
            viewHolder.course_id = convertView.findViewById(R.id.course_id);
            viewHolder.course_name = convertView.findViewById(R.id.course_name);
            viewHolder.course_name.setSelected(true);
            viewHolder.course_coach = convertView.findViewById(R.id.course_coach);
            viewHolder.course_coach.setSelected(true);
            viewHolder.course_time = convertView.findViewById(R.id.course_time);
            viewHolder.course_time.setSelected(true);
            viewHolder.course_rate = convertView.findViewById(R.id.course_rate);
            viewHolder.course_rate.setSelected(true);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        VReservecourse bean = mList.get(position);
        viewHolder.course_id.setText(bean.getRid().toString());
        viewHolder.course_name.setText(bean.getCoursename());
        viewHolder.course_coach.setText(bean.getName());
        viewHolder.course_time.setText(bean.getTime());
        viewHolder.course_rate.setText(bean.getRate());
        return convertView;
    }

    private static class ViewHolder {
        public TextView course_id;
        public TextView course_name;
        public TextView course_coach;
        public TextView course_time;
        public TextView course_rate;
    }
}
